﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.WebPages.Contact
{
    public partial class ClassWeibo : System.Web.UI.Page
    {
        TechnologySchoolEntities db = new TechnologySchoolEntities();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {               
                BindData();           
            }
        }

        private void InitRepeater()
        {
            ControlCollection cc = Page.Controls;
            foreach (Control c in cc)
            {
                if (c is Repeater)
                {
                    Repeater rep = c as Repeater;
                    rep.ItemDataBound += new RepeaterItemEventHandler(rep_ItemDataBound);
                }
            }
        }

        private void BindData()
        {
            var data = db.Weibo;

            //会计学
            Repeater1.DataSource = data.Where(d => d.Major == 0 && d.Grade == 1);
            Repeater1.DataBind();

            Repeater2.DataSource = data.Where(d => d.Major == 0 && d.Grade == 2);
            Repeater2.DataBind();

            Repeater3.DataSource = data.Where(d => d.Major == 0 && d.Grade == 3);
            Repeater3.DataBind();

            Repeater4.DataSource = data.Where(d => d.Major == 0 && d.Grade == 4);
            Repeater4.DataBind();

            //国贸
            Repeater5.DataSource = data.Where(d => d.Major == 1 && d.Grade == 1);
            Repeater5.DataBind();

            Repeater6.DataSource = data.Where(d => d.Major == 1 && d.Grade == 2);
            Repeater6.DataBind();

            Repeater7.DataSource = data.Where(d => d.Major == 1 && d.Grade == 3);
            Repeater7.DataBind();

            Repeater8.DataSource = data.Where(d => d.Major == 1 && d.Grade == 4);
            Repeater8.DataBind();

            //营销
            Repeater9.DataSource = data.Where(d => d.Major == 2 && d.Grade == 1);
            Repeater9.DataBind();

            Repeater10.DataSource = data.Where(d => d.Major == 2 && d.Grade == 2);
            Repeater10.DataBind();

            Repeater11.DataSource = data.Where(d => d.Major == 2 && d.Grade == 3);
            Repeater11.DataBind();

            Repeater12.DataSource = data.Where(d => d.Major == 2 && d.Grade == 4);
            Repeater12.DataBind();

            //国商
            Repeater13.DataSource = data.Where(d => d.Major == 3 && d.Grade == 1);
            Repeater13.DataBind();

            Repeater14.DataSource = data.Where(d => d.Major == 3 && d.Grade == 2);
            Repeater14.DataBind();

            Repeater15.DataSource = data.Where(d => d.Major == 3 && d.Grade == 3);
            Repeater15.DataBind();

            Repeater16.DataSource = data.Where(d => d.Major == 3 && d.Grade == 4);
            Repeater16.DataBind();

        }

        protected void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater4_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater5_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater6_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater7_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater8_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater9_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater10_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater11_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater12_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater13_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater14_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater15_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }

        protected void Repeater16_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Weibo item = e.Item.DataItem as Weibo;
                if (item.IsLinked.Value)
                {
                    HyperLink link = e.Item.FindControl("HyperLink1") as HyperLink;
                    link.Visible = true;
                    link.NavigateUrl = item.Url;
                    link.Text = item.ClassName;
                }
                else
                {
                    Literal literal = e.Item.FindControl("Literal1") as Literal;
                    literal.Visible = true;
                    literal.Text = item.ClassName;
                }
            }
        }
    }
}
